<%@codepage="65001"%>
<%session.codepage="65001"%>
<!-- #include virtual=/inc/dbConn.asp -->
<!-- #include virtual=/inc/function.asp -->
<!-- #include virtual=/inc/action.header.inc.asp -->

<%
	'## 파라미터 변수 선언부
	prdNm		= Request("findPrdNm")
	etcPrdCd	= Request("findEtcPrdCd")
	mkType		= Request("findMkType")
	goodsCnt		= Request("findGoods")
	prdGrp		= Request("findPrdGrp")

	If goodsCnt = "" Then goodsCnt = 0 End If 

	SQLTitle = "-- ■■■■ 제품 정보 그리드 List up ■■■■"
	
	'## 검색조건에 따른 조건절 만들기 
	If prdNm <> "" Then 
		addSql = " A.prdNm LIKE '%" & prdNm & "%' "
	End If 
	If etcPrdCd <> "" Then 
		If addSql <> "" Then addSql = addSql & " AND "
		addSql = addSql & " A.etcPrdCd LIKE '%" & etcPrdCd & "%' "
	End If 
	If prdGrp <> "" Then 
		If addSql <> "" Then addSql = addSql & " AND "
		addSql = addSql & " A.prdGrp = '" & prdGrp & "' "
	End If 
	If mkType <> "" Then 
		If addSql <> "" Then addSql = addSql & " AND "
		If mkType = "L" Then  
			addSql = addSql & " ISNULL(A.etcPrdCd,'')<>'' "
		Else
			addSql = addSql & " ISNULL(A.etcPrdCd,'')='' "
		End If 
	End If 
	If goodsCnt > 0 Then 
		If addSql <> "" Then addSql = addSql & " AND " END IF
		addSql = addSql & " ISNULL(C.totalGoods,0) >= " & goodsCnt
	End If 
	
	If Request.Cookies("S_level") = "05" Then 
		If addSql <> "" Then addSql = addSql & " AND " END IF
		addSql = addSql & " A.compCd = '" & Request.Cookies("S_compCd") & "' AND  ISNULL(A.etcPrdCd,'')<>'' AND A.flag='Y' "
	End If 

	If addSql <> "" Then 
		addSql = " WHERE " & addSql 
	End If 

	SQL = "SELECT A.prdCd, A.prdGrp, A.prdNm, A.etcPrdCd, A.part, A.remarks, A.flag, B.company, A.sourceSize, ISNULL(C.ttlGoods,0) totalQty, ISNULL(C.testedGoods,0) testedQty  FROM tblProduct A " & _
			" LEFT JOIN tblCompany B ON A.compCd=B.compCd " & _
			" LEFT JOIN (SELECT prdCd, SUM(goodsQty) ttlGoods, SUM(testedQty) testedGoods FROM tblOrder WHERE flag='Y' GROUP BY prdCd) C ON A.prdCd=C.prdCd " & addSql & _
			" ORDER BY A.flag DESC, A.prdNm" 

	If xMode="debug" Then 
		Call showDebug(SQLTitle,SQL) 
	End If 

	Set Rs=Server.CreateObject("ADODB.RecordSet")
	Rs.open SQL, DbCon, 1
	
	Response.write "<Products>" & vbcrlf

	If Rs.eof Or Rs.bof Then 
	Else 
		Do Until Rs.eof Or Rs.bof
		
			If Len(rs("remarks")) >7 Then 
				remarks = Left(rs("remarks"),7) & "..."
			Else
				remarks = rs("remarks")
			End If 
			if cdbl(rs("totalQty")) > cdbl(rs("testedQty"))  then
				goodsQty =  FormatNumber(rs("totalQty"),0) & "/0"  
			else				
				goodsQty =  FormatNumber(rs("totalQty"),0) & "/" & FormatNumber(cdbl(rs("testedQty"))-cdbl(rs("totalQty")),0)
			end if 
			goodsQty =  FormatNumber(rs("totalQty"),0) ' & "/" & FormatNumber(cdbl(rs("testedQty")),0)
			Response.write "	<PrdList>" & vbcrlf
				Call mkXMLNode("prdCd", rs("prdCd"), 2)
				Call mkXMLNode("prdGrp", rs("prdGrp"), 2)
				Call mkXMLNode("prdNm", rs("prdNm"), 2)
				Call mkXMLNode("etcPrdCd", rs("etcPrdCd"), 2)
				Call mkXMLNode("part", rs("part"), 2)
				Call mkXMLNode("remarks", remarks, 2)
				Call mkXMLNode("company", rs("company"), 2)
				Call mkXMLNode("totalGoods", goodsQty, 2)
				Call mkXMLNode("flag", Rs("flag"), 2)
			Response.write "	</PrdList>" & vbcrlf

		Rs.movenext
		Loop 
	End If
	Response.write "</Products>" & vbcrlf
'	Call rsWithXML("Save OK!")
%>